﻿# coding=utf-8
# /usr/bin/env python
import xlsxwriter, xlrd
import sys, os.path
fname = 'test.xlsx'
if not os.path.isfile(fname):
    print('文件路径不存在')
    sys.exit()
data = xlrd.open_workbook(fname)  # 打开fname文件
data.sheet_names()  # 获取xls文件中所有sheet的名称
table = data.sheet_by_index(0)  # 通过索引获取xls文件第0个sheet
nrows = table.nrows  # 获取table工作表总行数
ncols = table.ncols  # 获取table工作表总列数
workbook = xlsxwriter.Workbook('zm6.xlsx')  # 创建一个excel文件
worksheet = workbook.add_worksheet()  # 创建一个工作表对象
worksheet.set_column(0, ncols, 22)  # 设定列的宽度为22像素
temp=[[0 for i in range(ncols)]for j in range(nrows)]
for i in range(nrows):
    for j in range(ncols):
        temp[i][j] = table.cell_value(i, j, )  # 获取第i行中第j列的值
for i in range(nrows):
    for j in range(ncols):
        # cell_value=temp[i][j]
        # print(cell_value)
        worksheet.write(i, j, temp[i][j])
workbook.close()